package com.course.business.controller;


import com.course.server.dto.ResponseDto;
import com.course.server.exception.ValidatorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *@Author lin
 *@Data Created in 2020/8/2 16:47
 *Description 自定义异常
 *@Modified By
 *@Version V1.0
 */
@ControllerAdvice //@ControllerAdvice是@Controller增强器，可以对@Controller做统一的处理，如异常处理，数据处理等
public class ControllerExceptionHandler {
    private final static Logger LOG = LoggerFactory.getLogger(ControllerExceptionHandler.class);
    @ExceptionHandler(value = ValidatorException.class)
    @ResponseBody
    public ResponseDto validatorExceptionHandler(ValidatorException e){
        ResponseDto responseDto = new ResponseDto();
        responseDto.setSuccess(false);
        LOG.warn(e.getMessage());
        responseDto.setMessage("请求参数异常！");
        return responseDto;
    }
}
